package com.ch03;

/*
 * This class illustrates enums and exceptions
 * author: Mahesh
 */
public class Enums {
	private enum WeatherState {SUNNY, RAINY, HOT, COLD, FOGGY};
	
	private void printWeather(String s) throws EnumException {
		WeatherState.values();
		int no = 0;
		try {
			no = Integer.parseInt(s);
		} catch (NumberFormatException e) {
			throw new EnumException(s + " is not a number");
		}
		switch (no) {
		case 1:
			System.out.println(WeatherState.SUNNY);
			break;
		case 2:
			System.out.println(WeatherState.RAINY);
			break;
		case 3:
			System.out.println(WeatherState.HOT);
			break;
		case 4:
			System.out.println(WeatherState.COLD);
			break;
		case 5:
			System.out.println(WeatherState.FOGGY);
			break;	
		default:
			System.out.println("Not defined");
		}
	}
	public static void main(String args[]) {
		Enums obj = new Enums();
		if (args.length > 0) {
			try {
				obj.printWeather(args[0]);
			} catch (EnumException e) {
				System.out.println(e.getErrorMsg());
				//e.printStackTrace();
			}
		} else {
			try {
				obj.printWeather("1");
			} catch (EnumException e) {
				// TODO Auto-generated catch block
				//e.printStackTrace();
			}
		}
	}
}
